1
Pointers versus References: Understanding Aliases and Addresses
AI037 Lesson 4
00:00

The Anatomy of Compound Types

C++ compound types are defined by combining a base type with a type modifier. While both references and pointers provide indirection, they are philosophically distinct. A Reference (&) is a permanent alias—a nickname for an existing object. Once bound, it cannot be reseated. Conversely, a Pointer (*) is an independent object in memory that stores a hexadecimal address. It can be redirected to different objects or set to nullptr.

Visualizing the Memory

Memory [i] Label: i, r Memory [p] Value: 0x7FFD... (i) Reference: Same box, 2 names Pointer: Separate box stores address

In the code int *p1, p2;, only p1 is a pointer; p2 is a plain integer. To make both pointers, use int *p1, *p2;. This emphasizes that the modifier belongs to the individual declarator, not the base type.

main.py
TERMINAL bash — 80x24
> Ready. Click "Run" to execute.
>